/*************************************************************************
	> File Name: 019.P2820.局域网.cpp
	> Author: Maureen 
	> Mail: Maureen@qq.com 
	> Created Time: 六  6/26 15:08:36 2021
 ************************************************************************/

#include <iostream>
#include <algorithm>
using namespace std;

struct edge {
    int s, e, v;
    bool operator<(const edge &b) const {
        return this->v < b.v;
    }
};

edge edg[5005];
int n, k, ans, my_union[105], cnt;

int find_fa(int x) {
    if (my_union[x] == x) return x;
    return my_union[x] = find_fa(my_union[x]);
}

int main() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        my_union[i] = i;
    }
    
    int total = 0;
    for (int i = 0; i < k; i++) {
        cin >> edg[i].s >> edg[i].e >> edg[i].v;
        total += edg[i].v;
    }

    sort(edg, edg + k);
    for (int i = 0; i < k; i++) {
        int fa = find_fa(edg[i].s), fb = find_fa(edg[i].e);
        if (fa != fb) {
            ans += edg[i].v;
            my_union[fa] = fb;
            cnt++;
            if (cnt == n - 1) 
                break;
        }
    }
    
    cout << total - ans << endl;


    return 0;
}
